package com.koutao.mall.member.controller;

import java.util.Arrays;
import java.util.Map;

import com.koutao.mall.common.utils.PageUtils;
import com.koutao.mall.member.entity.MemberEntity;
import com.koutao.mall.member.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 会员
 *
 */
@Api("会员")
@Validated
@RestController
@RequestMapping("/member")
public class MemberController {
    @Autowired
    private MemberService memberService;


    /**
     * 列表
     */
    @ApiOperation("列表")
    @GetMapping("/list")
    //@RequiresPermissions("member:member:list")
    public PageUtils list(@RequestParam Map<String, Object> params){
        return memberService.queryPage(params);
    }


    /**
     * 信息
     */
    @ApiOperation("根据id查询")
    @GetMapping("/info/{id}")
    //@RequiresPermissions("member:member:info")
    public MemberEntity info(@PathVariable("id") Long id){
		return memberService.getById(id);
    }

    /**
     * 保存
     */
    @ApiOperation("新增")
    @PostMapping("/save")
    //@RequiresPermissions("member:member:save")
    public void save(@Valid @RequestBody MemberEntity member){
		memberService.save(member);
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PostMapping("/update")
    //@RequiresPermissions("member:member:update")
    public void update(@RequestBody MemberEntity member){
		memberService.updateById(member);
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @PostMapping("/delete")
    //@RequiresPermissions("member:member:delete")
    public void delete(@RequestBody Long[] ids){
		memberService.removeByIds(Arrays.asList(ids));
    }

}
